#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int t;
ll l,r;
int main()
{
    cin >> t;
    while(t --){
            cin >> l >> r;
        if(l == r){
            cout << 0 << endl;
            continue;
        }
        int i = 0;
        for(i = 63;i >= 0;i --){
            if((l >> i) != (r >> i)){
                ll res = ((ll)1 << (i + 1)) - (ll)1;
                cout << res << endl;
                break;
            }
        }
    }

    return 0;
}
